package com.itcpay.spring;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * IOC:依赖注入,依赖于某些方式给bean进行注入
 * 1、属性注入
 * 		set方法
 * 		<property name="type" value="小型犬"></property>
 * 		or
 * 		<property name="type">
 * 			<value>中型犬</value>
 * 		</property>
 * 2、构造器注入
 * 		按照顺序进行注入	<constructor-arg name="type" value="宝马"></constructor-arg>
 * 3、工厂方法(很少用，不推荐)
 * @author liufeng
 * @date 2017-6-11
 */
public class App 
{
    public static void main( String[] args )
    {
    	//创建容器
    	ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:application-context.xml");
    	//获取对象
    	Dog dog1 = (Dog) ac.getBean("dog1");
    	Dog dog2 = (Dog) ac.getBean("dog2");
    	Dog dog3 = (Dog) ac.getBean("dog3");
        System.out.println( "dog1：" + dog1.toString());
        System.out.println( "dog2：" + dog2.toString());
        System.out.println( "dog3：" + dog3.toString());
        
        Car car = (Car) ac.getBean("car");
        System.out.println("car:"+car.toString());
        
        /**
         * dog1：Dog [type=小型犬]
         * dog2：Dog [type=中型犬]
         * dog3：Dog [type=大型犬]
         * car:Car [type=宝马, factory=华晨, price=23000.0]
         */
    }
}
